package com.example.leetcode.leetcode;



import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author zht
 * @date 2021/1/12 9:34
 */
public class Solution139 {
    public static boolean wordBreak(String s, List<String> wordDict) {
        Set<String> words = new HashSet<>(wordDict);
        boolean [] tags = new boolean[s.length()+1];
        tags[0]=true;
        for (int i = 1; i <= s.length(); i++) {
            for (int j = 0; j <i; j++) {
                if(tags[j]&&words.contains(s.substring(j,i))){
                    tags[i]=true;
                    break;
                }
            }
        }

        return tags[s.length()];
    }

    public static void main(String[] args) {
        String s ="leetcode";
        List<String> wordDict =new ArrayList<>();
        wordDict.add("leet");
        wordDict.add("code");
        System.out.println(wordBreak(s,wordDict));
    }
}
